package dry.example.controller;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import dry.example.liteflow.UserContext;
import dry.example.service.NameService;
import dry.example.zhujie.AddLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Autowired
    NameService nameService;

    @Resource
    FlowExecutor flowExecutor;

    /**
     * http://127.0.0.1:10005
     */
    @AddLog(value = "9527")
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public Object index() {
        return nameService.a();
    }

    /**
     * http://127.0.0.1:10005/lite/flow
     */
    @RequestMapping(value = "lite/flow", method = RequestMethod.GET)
    public Object liteFlow() {
        UserContext user = new UserContext(1L, "zc", 2);
        LiteflowResponse response = flowExecutor.execute2Resp("chain1", null, user);
        System.out.println(response.getContextBean(UserContext.class).name);
        return "liteFlow";
    }

}
